﻿Imports OMANE.Common.UI
Imports OMANE.Common
Imports System.ComponentModel
Imports PTIC_Util

Namespace ViewModels
    Public Class TestData


        Private Shared ReadOnly Property RandomTrend As IEnumerable(Of DoublePoint)
            Get
                Dim rnd As New Random(Now.Millisecond)
                Dim result As New List(Of DoublePoint)
                For i As Integer = 0 To rnd.Next(25, 34)
                    result.Add(New DoublePoint(rnd.NextDouble(), rnd.NextDouble()))
                Next
                Return result
            End Get
        End Property
        Public ReadOnly Property Data As IEnumerable(Of DoublePoint)
            Get
                Return RandomTrend
            End Get
        End Property

        Private Shared _simpledata As List(Of SimplePoint)
        Public Shared ReadOnly Property SimpleData As IEnumerable
            Get
                If _simpledata Is Nothing Then
                    _simpledata = New List(Of SimplePoint)
                    Dim rnd As New Random(Now.Millisecond)
                    For i As Integer = 0 To rnd.Next(25, 34)
                        Dim x = Math.Ceiling(CDbl(i) + rnd.NextDouble() / CDbl(2))
                        _simpledata.Add(New SimplePoint(x, ((x - 15) ^ 2) + 20) With {.ExtraInfo = .X & "-" & .Y})
                    Next
                End If
                Return _simpledata
            End Get
        End Property
    End Class

    Public Class ChartPoint(Of XType, YType)
        Inherits ViewModelBase


        Public Sub New()

        End Sub
        Public Sub New(ByVal x As XType, ByVal y As YType)
            Me._X = x
            Me._Y = y
        End Sub
        Private _X As XType
        Public Property X As XType
            Get
                Return _X
            End Get
            Set(ByVal value As XType)
                OnPropertyChanging("X")
                'OnXChange(New PropertyChangeEventArgs(Of XType)(_X, value) With {.FinalValue = value})
                OnPropertyChanged("X")

            End Set
        End Property
        Protected Overridable Sub OnXChange(ByVal arg As PropertyChangeEventArgs(Of XType))
            RaiseEvent XChange(Me, arg)
            '_X = arg.FinalValue
        End Sub
        Public Event XChange As EventHandler(Of PropertyChangeEventArgs(Of XType))



        Private _Y As YType
        Public Property Y As YType
            Get
                Return _Y
            End Get
            Set(ByVal value As YType)
                OnPropertyChanging("Y")
                'OnYChange(New PropertyChangeEventArgs(Of YType)(_Y, value) With {.FinalValue = value})
                OnPropertyChanged("Y")

            End Set
        End Property
        Protected Overridable Sub OnYChange(ByVal arg As PropertyChangeEventArgs(Of YType))
            RaiseEvent YChange(Me, arg)
            '_Y = arg.FinalValue
        End Sub
        Public Event YChange As EventHandler(Of PropertyChangeEventArgs(Of YType))


        Public Property ExtraInfo As String

    End Class


    Public Class DoublePoint
        Inherits ChartPoint(Of Double, Double)

        Sub New(ByVal x As Double, ByVal y As Double)
            MyBase.New(x, y)
        End Sub

    End Class

    Public Class SimplePoint
        Inherits ViewModelBase

        Sub New()

        End Sub
        Sub New(ByVal x As Double, ByVal y As Double)
            _X = x
            _Y = y
        End Sub


        Private _X As Double
        Public Property X As Double
            Get
                Return _X
            End Get
            Set(ByVal value As Double)
                OnPropertyChanging("X")
                'OnXChange(New PropertyChangeEventArgs(Of Double)(_X, value) With {.FinalValue = value})
                OnPropertyChanged("X")

            End Set
        End Property
        Protected Overridable Sub OnXChange(ByVal arg As PropertyChangeEventArgs(Of Double))
            RaiseEvent XChange(Me, arg)
            '_X = arg.FinalValue
            _ExtraInfo = String.Format("X = {0} & Y = {1}", String.Format("0.00", _X), String.Format("0.00", _Y))
        End Sub
        Public Event XChange As EventHandler(Of PropertyChangeEventArgs(Of Double))


        Private _Y As Double
        Public Property Y As Double
            Get
                Return _Y
            End Get
            Set(ByVal value As Double)
                OnPropertyChanging("Y")
                'OnYChange(New PropertyChangeEventArgs(Of Double)(_Y, value) With {.FinalValue = value})
                OnPropertyChanged("Y")

            End Set
        End Property
        Protected Overridable Sub OnYChange(ByVal arg As PropertyChangeEventArgs(Of Double))
            RaiseEvent YChange(Me, arg)
            '_Y = arg.FinalValue
            _ExtraInfo = String.Format("X = {0} & Y = {1}", String.Format("0.00", _X), String.Format("0.00", _Y))

        End Sub
        Public Event YChange As EventHandler(Of PropertyChangeEventArgs(Of Double))



        Private _ExtraInfo As Object
        Public Property ExtraInfo As Object
            Get
                Return _ExtraInfo
            End Get
            Set(ByVal value As Object)
                OnPropertyChanging("ExtraInfo")
                'OnExtraInfoChange(New PropertyChangeEventArgs(Of Object)(_ExtraInfo, value) With {.FinalValue = value})
                OnPropertyChanged("ExtraInfo")

            End Set
        End Property
        Protected Overridable Sub OnExtraInfoChange(ByVal arg As PropertyChangeEventArgs(Of Object))
            RaiseEvent ExtraInfoChange(Me, arg)
            '_ExtraInfo = arg.FinalValue
        End Sub
        Public Event ExtraInfoChange As EventHandler(Of PropertyChangeEventArgs(Of Object))


    End Class
End Namespace
